//
//  AlarmAPI.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/4/24.
//

import Foundation
import HandyJSON

// MARK: - 报警通知

// MARK: - URL
let URLAlarmCbfCount = "/alarm/queryAlarmCbfCount" /// 撤布防统计
let URLAlarmCbfByTbCompanyId = "/alarm/queryAlarmCbfByTbCompanyId" /// 网点撤布防信息
let URLAlarmCbfqyCount = "/alarm/queryAlarmCbfqyCount" /// 区域类型统计-撤布防
let URLAlarmCountByType = "/alarm/queryAlarmCountByType" /// 报警类型统计
let URLAlarmList = "/alarm/queryAlarmList" /// 报警列表
let URLAlarmById = "/alarm/queryAlarmById" /// 报警信息详情
let URLAlarmHandleById = "/alarm/queryAlarmHandleById" /// 报警处置回复
let URLAlarmStatics = "/alarm/queryAlarmStatics" /// 预警统计
let URLAlarmByType = "/alarm/queryAlarmByType" // 根据报警类型统计

let URLAlarmCbfdepts = "/alarm/cbfdepts" // 今日未布防-网点
let URLAlarmCbfinfo = "/alarm/cbfinfo" // 今日未布防-布防详情

// MARK: - API

struct AlarmCommonParam: Encodable {
    var pageNum: Int?
    var pageSize: Int?
    var dateType: String? // 时间类型： 1 最近24小时  2 最近三天  3 最近七天 ；不填默认最近24小时
    var tbCompanyId: String? // 公司id
    var status: String?  // 处置状态 1处置  0 未处置
    
    var timestamp: String?
    var signature: String?
    
    init(pageNum: Int? = nil, pageSize: Int? = nil, dateType: String? = nil, tbCompanyId: String? = nil, status: String? = nil) {
        self.pageNum = pageNum
        self.pageSize = pageSize
        self.dateType = dateType
        self.tbCompanyId = tbCompanyId
        self.status = status
    }
}

struct AlarmParam: Encodable {
    var tbId: Int64?  // 报警信息ID
    var remark: String? // 回复内容
    
    var timestamp: String?
    var signature: String?
    
    init(tbId: Int64? = nil, remark: String? = nil) {
        self.tbId = tbId
        self.remark = remark
    }
}

struct AlarmStaticsParam: Encodable {
    var date: String?  // 2022-04-19
    var dateType: String? // 日期类型 1 日 2 月  3 年
    var tbCompanyId: String? // 网点ID
    var tbAlarmType: String? // 报警类型
    
    var timestamp: String?
    var signature: String?
    
    init(date: String? = nil, dateType: String? = nil, tbCompanyId: String? = nil, tbAlarmType: String? = nil) {
        self.date = date
        self.dateType = dateType
        self.tbCompanyId = tbCompanyId
        self.tbAlarmType = tbAlarmType
    }
}

struct AlarmWBFParam: Encodable {
    var date: String?  // 2022-04-19
    var deptId: String? // 网点ID
    var abfType: String? // 报警类型
    
    var timestamp: String?
    var signature: String?
    
    init(date: String? = nil, deptId: String? = nil, abfType: String? = nil) {
        self.date = date
        self.deptId = deptId
        self.abfType = abfType
    }
}

extension API {

    /// 撤布防统计
    class func getAlarmCbfCount(withParam _param: AlarmCommonParam, block: ResponseBlock<AlarmCbfCountModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCbfCount, method: .get, parameters: param, modelType: AlarmCbfCountModal.self, resultBlock: block)
    }
    
    /// 网点撤布防信息
    class func getAlarmCbfByTbCompanyId(withParam _param: AlarmCommonParam, block: ResponseBlock<AlarmCbfModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCbfByTbCompanyId, method: .get, parameters: param, modelType: AlarmCbfModal.self, resultBlock: block)
    }
    
    /// 区域类型统计-撤布防
    class func getAlarmCbfqyCount(withParam _param: AlarmCommonParam, block: ResponseBlock<AlarmCbfqyCountModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCbfqyCount, method: .get, parameters: param, modelType: AlarmCbfqyCountModal.self, resultBlock: block)
    }
    
    /// 报警类型统计
    class func getAlarmCountByType(withParam _param: AlarmCommonParam, block: ResponseBlock<AlarmCountByTypeModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCountByType, method: .get, parameters: param, modelType: AlarmCountByTypeModal.self, resultBlock: block)
    }

    /// 报警列表
    class func getAlarmList(withParam _param: AlarmCommonParam, block: ResponseBlock<AlarmsModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmList, method: .get, parameters: param, modelType: AlarmsModal.self, resultBlock: block)
    }
    
    /// 报警信息详情
    class func getAlarmDetail(withParam _param: AlarmParam, block: ResponseBlock<AlarmsModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmById, method: .get, parameters: param, modelType: AlarmsModal.self, resultBlock: block)
    }
    
    /// 报警处置回复
    class func postAlarmDetail(withParam _param: AlarmParam, block: ResponseBlock<RespModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmHandleById, parameters: param, modelType: RespModal.self, resultBlock: block)
    }

    /// 预警统计
    class func getAlarmStatics(withParam _param: AlarmStaticsParam, block: ResponseBlock<AlarmStaticsModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmStatics, method: .get, parameters: param, modelType: AlarmStaticsModal.self, resultBlock: block)
    }

    /// 根据报警类型统计
    class func getAlarmStaticsByType(withParam _param: AlarmStaticsParam, block: ResponseBlock<AlarmByTypeModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmByType, method: .get, parameters: param, modelType: AlarmByTypeModal.self, resultBlock: block)
    }
    
    /// 今日未布防-网点
    class func getAlarmCbfdepts(withParam _param: AlarmWBFParam, block: ResponseBlock<AlarmCbfdeptsModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCbfdepts, method: .get, parameters: param, modelType: AlarmCbfdeptsModal.self, resultBlock: block)
    }

    /// 今日未布防-布防详情
    class func getAlarmCbfinfo(withParam _param: AlarmWBFParam, block: ResponseBlock<AlarmCbfinfoModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLAlarmCbfinfo, method: .get, parameters: param, modelType: AlarmCbfinfoModal.self, resultBlock: block)
    }
}

/// 撤布防统计
struct AlarmCbfCountModal: HandyJSON {
    var cfCount: Int64 = 0 //撤防数
    var bfCount: Int64 = 0 //布防数
    var parent: String? //布防率
}

/// 网点撤布防信息
struct AlarmCbfModal: HandyJSON {
    var createTime: String?  //创建时间
    var updateTime: String?  //更新时间
    var tbId: Int64?
    var tbCompanyId: Int64? //公司（部门）id
    var tbWebsiteName: String? //网点名称
    var tbAlarmType: String? //5 撤防   6 布防
    var tbPositionType: String?//区域类型 1 营业网点 2 ATM 3 离行自助 4 办公区域 5 金库
    var tbAlarmTime: String? //撤布防时间
    var tbDeviceCode: String?
    var tbDeviceName: String? //设备名称
    var tbDevicePosition: String? //设备区域
}

/// 区域类型统计-撤布防
struct AlarmCbfqyCountModal: HandyJSON {
    var dictLabel: String? // 区域类型 "营业网点"
    var dictValue: String?
    var total: Int64 = 0 //总数
    var bfTotal: Int64 = 0 //布防数
    var cfTotal: Int64 = 0 //撤防数
}

/// 报警类型统计
struct AlarmCountByTypeModal: HandyJSON {
    var dictLabel: String? // 报警类型
    var dictValue: String?
    var total: Int64 = 0 //总数
}

/// 报警列表
/// 报警信息详情
struct AlarmsModal: HandyJSON {
    var createTime: String?  //创建时间
    var updateTime: String?  //更新时间
    var tbId: Int64?
    var tbCompanyId: Int64? //公司（部门）id
    var tbWebsiteName: String? //网点名称
    var tbAlarmType: String? //报警类型
    var tbPositionType: String?//区域类型 1 营业网点 2 ATM 3 离行自助 4 办公区域 5 金库
    var tbAlarmTime: String? //报警时间
    var tbDeviceCode: String? //设备号
    var tbDeviceName: String? //设备名称
    var tbDevicePosition: String? //设备区域
    
    var remark: String? //报警处置回复
    var status: String? //处置状态： 1处置  0 未处置
    var tbHandleId: String? //处置人ID
    var tbHandleName: String? //处置人名称
    
    var tbAlarmPic: [String]? //报警图片
    var tbAlarmVideo: [String]? //报警视频
}

/// 预警统计
struct AlarmStaticsModal: HandyJSON {
    var yjTotal: Int64? //预警总数
    var hbTotal: Int64? //预警总数
    var typeList: [AlarmStaticsTypeListModal]? // 报警类型统计列表
    var hbRatio: String? //环比率
    var zxtList: [AlarmStaticsZxtListModal]? //折线图统计列表
}

struct AlarmStaticsTypeListModal: HandyJSON {
    var dictLabel: String? //类型名称
    var dictValue: String? //类型名称
    var total: Int64? //类型统计总数
}

struct AlarmStaticsZxtListModal: HandyJSON {
    var date: String? //周期
    var total: Int64? //周期统计数
}

/// 根据报警类型统计
struct AlarmByTypeModal: HandyJSON {
    var yjTotal: Int64? ////本年总数
    var hbRatio: String? //环比率
    var avgCz: String? //平均处置时间
    var sjqs: [AlarmBySjqsModal]? //数据趋势
    var sjfb: [AlarmBySjfbModal]? //时间分布
}

struct AlarmBySjqsModal: HandyJSON {
    var date: String? //时间点
    var total: Int64? //总数
}

struct AlarmBySjfbModal: HandyJSON {
    var date: String? //时间点
    var total: Int64? //总数
}

/// 今日未布防-网点
struct AlarmCbfdeptsModal: HandyJSON {
    var list: [AlarmCbfdeptsListpModal]?
    var totalMap: AlarmCbfdeptsTotalMapModal?
}

struct AlarmCbfdeptsListpModal: HandyJSON {
    var id: String? // 102",
    var label: String? // 自贸区分行
    var wdlxr: String? // 自贸区分行
    var wdlxrhm: String? // 38458754(分行
    var deptPosition: String? // 上海市浦东新区长清北路53号中铝大厦南楼大堂部分、南楼6层
    var sfczzj: String? // 1
    var ybfTotal: Int64? //  0
    var unbfTotal: Int64? // 0
    var ycbfTotal: String? // 0
}

struct AlarmCbfdeptsTotalMapModal: HandyJSON {
    var id: String? // 103
    var label: String? // 浦东分行
    var wdlxr: String? // 浦东分行
    var wdlxrhm: String? // 021-6840968
    var deptPosition: String? // 上海市张杨路699号
    var sfczzj: String? // 1
    var ybfTotal: Int64? // 3
    var unbfTotal: Int64? // 0
    var ycbfTotal: String? // 0
}

/// 今日未布防-布防详情
struct AlarmCbfinfoModal: HandyJSON {
    var wddm: String? // 1030203
    var wdmc: String? // 洋泾支行
    var wdfj: String? // 陆家嘴支行
    var wdzrr: String? // 网点管理员
    var wdzrrhm: String? // 58603405
    var wddz: String? // 上海市沈家弄路1101号1楼
    var rwzq: String? // 0
    var tjsj: String? // 2023-06-05 17:48:21
    var lzrmc: String? // 安保负责人
    var bagsmc: String? // 保安公司
    var deviceList: [AlarmCbfinfoDeviceModal]?
}

struct AlarmCbfinfoDeviceModal: HandyJSON {
    var tbId: Int64? // 26
    var tbCompanyId: Int64? // 1030203
    var tbWebsiteName: String? // 真北路支行
    var tbAlarmType: String? // 6
    var tbPositionType: String? // 1
    var tbAlarmTime: String? // 2023-06-05 17:48:21
    var dateType: String? //
    var tbDeviceCode: String? // a97885b7-e38f-4706-a6ff-ae27a55e2809
    var tbDeviceName: String? //
    var tbDevicePosition: String? // 大门右,言助银行门口 江外
    var status: String? //
}
